// JavaScript Document

/***** FUNCTIES GEBRUIKT DOOR contact.html *****/

function geolocatie() {
		var directionsService = new google.maps.DirectionsService(),
			directionsDisplay = new google.maps.DirectionsRenderer(),
			createMap = function (start) {
				var travel = {
						origin : (start.coords)? new google.maps.LatLng(start.lat, start.lng) : start.address,
						destination : "Erasmushogeschool Brussel, Nijverheidskaai, Anderlecht",
						travelMode : google.maps.DirectionsTravelMode.DRIVING
					},
					mapOptions = {
						zoom: 10,
						center : new google.maps.LatLng(50.842238, 4.322808),
						scrollwheel: false,
						mapTypeId: google.maps.MapTypeId.ROADMAP
					};

				map = new google.maps.Map(document.getElementById("map"), mapOptions);
				directionsDisplay.setMap(map);
				directionsDisplay.setPanel(document.getElementById("map-directions"));
				directionsService.route(travel, function(result, status) {
					if (status === google.maps.DirectionsStatus.OK) {
						directionsDisplay.setDirections(result);
					}
				});
			};

			// Check for geolocation support	
			if (navigator.geolocation) {
				navigator.geolocation.getCurrentPosition(function (position) {
						// Success!
						createMap({
							coords : true,
							lat : position.coords.latitude,
							lng : position.coords.longitude
							
						});
						
						/* h2 element van maps herschrijven opdat de webgebruiker het 'maps' tapje niet vroegtijdig dicht klapt. 
							Vooraleer de gebruiker deze tab wil inklappen, moet de map geladen zijn, wil de map blijven werken. */
						document.getElementById('maps_titel').innerHTML = "Route <span class=\"klein\"><a href=\"javascript:void(0)\" id=\"togglemap\">Hide</a></span>";
						document.getElementById('directions_titel').innerHTML = "Route details <span class=\"klein\"><a href=\"javascript:void(0)\" id=\"togglemap-directions\">Show</a></span>";
						document.getElementById('directions_titel').style.display = "block";
					}, 
					function () {
						// Gelocation fallback: Defaults to Erasmushogeschool Brussel, Nijverheidskaai, Anderlecht
						document.getElementById('maps_titel').innerHTML = "Map <span class=\"klein\"><a href=\"javascript:void(0)\" id=\"togglemap\">Hide</a></span>";
						document.getElementById('directions_titel').style.display = "none";
						createMap({
							coords : false,
							address : "Erasmushogeschool Brussel, Nijverheidskaai, Anderlecht"
						});
					}
				);
			}
			else {
				// No geolocation fallback: Defaults to Erasmushogeschool Brussel, Nijverheidskaai, Anderlecht
				document.getElementById('directions_titel').innerHTML = "Route details <span class=\"klein\"><a href=\"javascript:void(0)\" id=\"togglemap-directions\">Show</a></span>";
				createMap({
					coords : false,
					address : "Erasmushogeschool Brussel, Nijverheidskaai, Anderlecht"
				});
				
				
			}
			
			
}